import { count, formatTen } from '../../../assets/js/help.js'
import api from '../../../fetch/api'

export default {
    data() {
        return {
            bigImgPath: ''
        }
    },
    created() {
        this.getItemList();
    },
    methods: {
        getList() {
            this.getItemList(this.searchParams);
        },
        examineModal_open(index, id) {
            console.log('examineModal_open', index, id)

            this.examineData.spaceId = id;
            this.examineData.status = 'ADUIT_PASS';
            this.examineData.parkingSpaceNumber = this.tbodysInfo[index].parkingSpaceNumber;
            this.examineData.remark = '';
            this.toOpenModal('examineModal');
        },
        //获取列表
        getItemList(aparams) {
            let self = this,
                params = {
                    page: this.pageNumber,
                    rp: this.pageSize
                };
            params = $.extend({}, params, aparams);
            // API.coupon.GetTraderListData(params)
            api.fetchGet('/share/list.do', params)
                .then(res => {
                    console.log('getListResult', res)
                    let data = res.data,
                        list = data.rows;
                    self.tbodysInfo = list;
                    self.total = data.total;
                }, err => { })
        },
        examineModal_save(event, formName) {
            let self = this;
            let params = self.examineData;
            self.$refs[formName].validate((valid) => {
                if (valid) {
                    api.fetchPost('/share/audit.do', params).then(response => {
                        console.log('examineModal_save ==== response', response);
                        if (response.status == 1) {
                            // icon: 0:普通提示 1：正确的提示 2： 错误提示
                            // time: 不填默认1000ms
                            self.showToast(response.message, 1, 2000);
                            self.closed('examineModal');
                            self.getList();
                        } else {
                            self.showToast(res.message, 2, 2000)
                            return;
                        }
                    }, err => {
                        console.log(err);
                    })
                    // self.httpPost('./share/audit.do', params)
                    // this.closed('examineModal');
                    // this.getRoleList();
                } else {
                    console.log('error submit!!');
                }
            });
        },

    },
    filters: {
        listToStr(list) {
            var str = '';
            function getLocalTime(value) {
                let result = '';
                if (value) {
                    let date = new Date(value);
                    result = date.getFullYear() + "-" + formatTen(date.getMonth() + 1) + "-" + formatTen(date.getDate()) + " " + formatTen(date.getHours()) + ":" + formatTen(date.getMinutes()) + ":" + formatTen(date.getSeconds());
                }
                return result;
            }
            list.forEach(function (element) {
                str += getLocalTime(element.excludeFrom) + "至" + getLocalTime(element.excludeTo) + "；"
            }, this);
            return str;
        },
        status(num) {
            switch (num) {
                case 0:
                    return "待审核"
                    break;
                case 1:
                    return "审核通过"
                    break;
                case 2:
                    return "审核拒绝"
                    break;
                case 3:
                    return "启用"
                    break;
                case 4:
                    return "暂停"
                    break;
                default:
                    break;

            }
        }

    }

}